Skip to content

Add a web (browser) front-end and an example web app#90

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/web-interface
Jun 13, 2026
Merged

Add a web (browser) front-end and an example web app#90
dmccoystephenson merged 1 commit into
mainfrom
feature/web-interface

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

Adds a third front-end behind the existing BaseUserInterface contract — a browser-based web interface — plus an example app that runs the whole game in the browser. No new dependencies (Python standard library only).

  • src/ui/webUserInterface.pyWebUserInterface(BaseUserInterface). The synchronous game loop is unchanged: each input primitive (showOptions, showDialogue, promptForText, timedKeyPress) publishes the current "screen" and blocks until the browser responds, via a thread-safe rendezvous (queue.Queue + a versioned screen snapshot). A daemon-thread http.server serves the page (GET /), the screen state (GET /state), and accepts responses (POST /input). showInteractiveDialogue/promptForNumber are inherited from the base, so NPC dialogue and numeric prompts work for free.
  • UIType.WEB + a lazy factory branch (so console/pygame modes don't start the HTTP machinery).
  • FishE(interfaceType=...) — optional, default unchanged — lets a caller pick a front-end without editing the module constant.
  • examples/web_app.pypython3 examples/web_app.py, open http://127.0.0.1:8000.
  • README documents it.

Test plan

  • python3 -m compileall -q src clean
  • SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy python3 -m pytest — 198 passed
  • New tests/ui/test_webUserInterface.py: implements the interface; showOptions/promptForText/promptForNumber/showDialogue/timedKeyPress round-trip via the rendezvous; invalid options ignored; and a real ephemeral-port HTTP smoke test (serves /, /state, accepts /input).
  • Manual end-to-end smoke: the example app serves the page, runs the save-file manager in-browser, creates a save, and renders the in-game screen (full header) entirely over HTTP.

🤖 Generated with Claude Code

Implements WebUserInterface, a third BaseUserInterface front-end alongside the
console and pygame ones, using only the Python standard library. The
synchronous game loop is unchanged: each input primitive publishes the current
"screen" and blocks until the browser submits a response, coordinated through a
thread-safe rendezvous; a small stdlib http.server serves the page (GET /),
the current screen (GET /state), and accepts the player's response (POST /input).

- UIType.WEB + a lazy factory branch (so other modes don't start HTTP machinery).
- FishE accepts an interfaceType (default unchanged) so a front-end can be chosen
  without editing the module constant.
- examples/web_app.py runs the whole game in the browser.

The entire game — save manager, fishing, shop, bank, tavern, NPC dialogue —
works through the web UI with no new dependencies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@dmccoystephenson dmccoystephenson left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self-review:

  • Scope: PASS — WebUserInterface + UIType.WEB + lazy factory branch + FishE interfaceType param + example app + README + tests.
  • Dependencies: PASS — Python standard library only (http.server, queue, threading); pygame/console modes unaffected (lazy import).
  • Abstraction/DRY: PASS — implements the BaseUserInterface primitives; inherits showInteractiveDialogue and promptForNumber, so dialogue/numeric input work without web-specific code.
  • Tests: PASS — 198; rendezvous round-trips for every primitive + invalid-option handling + a real ephemeral-port HTTP smoke test; manual end-to-end of the example app verified.
  • Safety: default front-end unchanged; no schema/persistence/save-file paths touched.
  • CI: PASS.

@dmccoystephenson dmccoystephenson merged commit d316ee8 into main Jun 13, 2026
1 check passed
@dmccoystephenson dmccoystephenson deleted the feature/web-interface branch June 13, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant